9 typedef pair
<int, int> node
;
10 typedef map
<node
, set
<node
> > graph
;
19 void dfs(const node
&u
){
20 set
<node
> &vecinos
= g
[u
];
21 for (set
<node
>::iterator i
= vecinos
.begin(); i
!= vecinos
.end(); ++i
){
23 if (d
[*i
] + 1 < d
[u
]){
24 printf("Cycle from (%d, %d) to (%d, %d)\n", i
->first
, i
->second
, u
.first
, u
.second
);
26 longest
= max(longest
, d
[u
] - d
[*i
] + 1);
38 while (cin
>> w
>> h
&& w
&& h
){
45 for (int i
=0; i
<w
; ++i
){
46 for (int j
=0; j
<h
; ++j
){
48 g
[node(2*i
, j
)].insert(node(2*i
, j
-1));
49 g
[node(2*i
, j
-1)].insert(node(2*i
, j
));
51 g
[node(2*i
+1, j
)].insert(node(2*i
+1, j
+1));
52 g
[node(2*i
+1, j
+1)].insert(node(2*i
+1, j
));
59 g
[node(2*i
+1, j
)].insert(node(2*i
, j
));
60 g
[node(2*i
, j
)].insert(node(2*i
+1, j
));
63 g
[node(2*i
, j
)].insert(node(2*i
+1, j
));
64 g
[node(2*i
+1, j
)].insert(node(2*i
, j
));
68 g
[node(2*i
,j
)].insert(node(2*i
-1, j
));
69 g
[node(2*i
-1,j
)].insert(node(2*i
, j
));
72 g
[node(2*i
+1,j
)].insert(node(2*i
+2, j
));
73 g
[node(2*i
+2,j
)].insert(node(2*i
+1, j
));
77 cerr
<< "Unrecognized char in input" << endl
;
82 /*for (map<node, set<node> >::iterator i = g.begin(); i != g.end(); ++i){
83 printf("Vecinos de (%d, %d):\n", i->first.first, i->first.second);
84 set<node> v = i->second;
85 for (set<node>::iterator j = v.begin(); j != v.end(); ++j){
86 printf("(%d, %d) ", j->first, j->second);
91 for (map
<node
, set
<node
> >::iterator i
= g
.begin(); i
!= g
.end(); ++i
){
92 if (d
.count(i
->first
) == 0){
98 printf("Maze #%d:\n", mazeNo
++);
100 printf("There are no cycles.\n");
102 printf("%d Cycles; the longest has length %d\n", qty
, longest
);